package com.wudl.govern.controller;

import com.wudl.common.api.CommonResult;

import com.wudl.govern.domain.MetaTriggerHistory;
import com.wudl.govern.service.MetaTriggerHistoryService;
import com.wudl.govern.vo.MetaTriggerHistoryVO;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;
import java.util.ArrayList;

/**
 * meta_trigger_history Service
 *
 * @author wudl
 */
@Api
@RestController
@RequestMapping("/metaTriggerHistory")
public class MetaTriggerHistoryController {

    @Autowired
    private MetaTriggerHistoryService metaTriggerHistoryService;

    /**
     * 分页查询
     */
    @PostMapping("/page")
    public CommonResult<List<MetaTriggerHistoryVO>> page(@RequestBody MetaTriggerHistoryVO pageVO, @RequestParam Integer page, @RequestParam Integer size) {

        List<MetaTriggerHistoryVO> MetaTriggerHistoryVoList = new ArrayList<>();
  // 拷贝结果
        List<MetaTriggerHistory> MetaTriggerHistoryList = metaTriggerHistoryService.page(page, size);

        for (MetaTriggerHistory metaTriggerHistoryTmp:MetaTriggerHistoryList )
        {
            MetaTriggerHistoryVO metaTriggerHistoryVO = new MetaTriggerHistoryVO();
            BeanUtil.copyProperties(metaTriggerHistoryTmp, MetaTriggerHistoryVO.class);
            MetaTriggerHistoryVoList.add(metaTriggerHistoryVO);
        }
        return CommonResult.success(MetaTriggerHistoryVoList);


    }

    /**
     * 查询详情
     */
    @GetMapping("/get/{id}")
    public CommonResult<MetaTriggerHistoryVO> get(@PathVariable Integer id) {
        MetaTriggerHistory entity = metaTriggerHistoryService.getById(id);
        return CommonResult.success(BeanUtil.copyProperties(entity, MetaTriggerHistoryVO.class));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public CommonResult<Void> add(@RequestBody MetaTriggerHistoryVO addVO) {
        metaTriggerHistoryService.save(BeanUtil.copyProperties(addVO, MetaTriggerHistory.class));
        return CommonResult.success();
    }

    /**
     * 编辑
     */
    @PutMapping("/edit")
    public CommonResult<Void> edit(@RequestBody MetaTriggerHistoryVO editVO) {
        metaTriggerHistoryService.updateById(BeanUtil.copyProperties(editVO, MetaTriggerHistory.class));
        return CommonResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public CommonResult<Void> delete(@PathVariable Integer id) {
        metaTriggerHistoryService.removeById(id);
        return CommonResult.success();
    }

}
